package org.moonlight.jvm.classpath.entry;

import lombok.EqualsAndHashCode;
import org.moonlight.jvm.classpath.Entry;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 目录形式的类路径
 *
 * @author Moonlight
 * @createTime 2023/8/14 14:57
 **/
@EqualsAndHashCode
public class DirEntry implements Entry {

    /** 目录的绝对路径 **/
    private final Path absPath;

    public DirEntry(String path) {
        this.absPath = Paths.get(path).toAbsolutePath();
    }

    @Override
    public byte[] readClass(String className) throws IOException {
        return Files.readAllBytes(absPath.resolve(className));
    }

    @Override
    public String toString() {
        return absPath.toString();
    }
}
